var vm = new Vue({
	el: '#app',
	data: {
		host: host,
		user_id: sessionStorage.user_id || localStorage.user_id,
		token: sessionStorage.token || localStorage.token,
		username: sessionStorage.username || localStorage.username,
		old_password: '',
		new_password: '',
		quit_new_password: '',
		error_password_message: '',
		error_password: false
	},

	methods: {
		logout: function () {
			sessionStorage.clear();
			localStorage.clear();
			location.href = '/login.html';
		},

		change_password: function () {
			axios.put(this.host + '/change_password/', {
				'password': this.old_password,
				'password2': this.new_password,
				'password3': this.quit_new_password
				},{
					headers: {
							'Authorization': 'JWT ' + this.token
				},
					responseType: 'json'
			})
			.then(response => {
				this.error_password = false;
				this.error_password_message = '';
				alert('修改密码成功，请重新登录')
				sessionStorage.clear();
				localStorage.clear();
				location.href = '/login.html?next=/user_center_pass.html';
			})
			.catch(error => {
				if (error.response.status == 400) {
					this.error_password = true;
					this.error_password_message = error.response.data.non_field_errors[0];
				}
			})
		}
	}
})